const mixins = require("../../common/mixins/index");
const {Home} = require("../../models/home");
import Toast from "../../miniprogram/miniprogram_npm/@vant/weapp/toast/toast"
Page({
    data: {
        isTop: true
    },

    async onConfirm() {
        const code = this.data.info && this.data.info.code
        if (!code || !code.trim()) {
            Toast.fail({
                message: '请输入兑换码'
            })
            return
        }
        const res = await Home.exchangeCoinByCode(code)
        if (res.status === 200) {
            Toast.success({
                message: '兑换成功',
                forbidClick: true
            })
            this.setData({[`info.code`]: ''})
        } else {
            Toast.fail({
                message: '兑换失败',
                forbidClick: true
            })
        }
    },

    onInput(e) {
        mixins.onInput(e, this)
    },

    onPageScroll(e) {
        mixins.onPageScroll(e, this, 'isTop')
    },
});
